package com.everest.tribalapp;

import java.text.SimpleDateFormat;
import java.util.Calendar;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class Add1 extends Activity implements OnClickListener {
	// http://prefiles.com/p0jjuc0qoqav/Packtpub.Unity.3.Game.Development.Hotshot.Aug.2011.rar
	private LinearLayout home;
	private LinearLayout add;
	private LinearLayout setting;
	private LinearLayout logout;
	private TextView username;
	private TextView dat;
	private RelativeLayout dering;
	private RelativeLayout dering_masyarakat;
	private RelativeLayout dering_pemerintah;
	private RelativeLayout dering_pengelola;
	private RelativeLayout dering_masyarakat_2013;
	private RelativeLayout dering_pemerintah_2013;
	private RelativeLayout dering_pengelola_2013;
	private RelativeLayout desa;
	private RelativeLayout desa_masyarakat;
	private RelativeLayout desa_masyarakat_2013;
	private RelativeLayout desa_pemerintah;
	private RelativeLayout desa_pemerintah_2013;
	private RelativeLayout desa_pengelola;
	private RelativeLayout desa_pengelola_2013;
	private RelativeLayout PILK;
	private RelativeLayout PILK_masyarakat;
	private RelativeLayout PILK_masyarakat_2013;
	private RelativeLayout PILK_pemerintah;
	private RelativeLayout PILK_pemerintah_2013;
	private RelativeLayout PILK_pengelola;
	private RelativeLayout PILK_pengelola_2013;
	private LinearLayout dering_l1;
	private LinearLayout desa_l1;
	private LinearLayout PILK_l1;
	private LinearLayout dering_PENGELOLA_l1;
	private LinearLayout dering_PEMERINTAH_l1;
	private LinearLayout dering_MASYARAKAT_l1;
	private LinearLayout desa_PENGELOLA_l1;
	private LinearLayout desa_PEMERINTAH_l1;
	private LinearLayout desa_MASYARAKAT_l1;
	private LinearLayout PILK_PENGELOLA_l1;
	private LinearLayout PILK_PEMERINTAH_l1;
	private LinearLayout PILK_MASYARAKAT_l1;
	private int dering_l1_flag = 0;
	private int desa_l1_flag = 0;
	private int PILK_l1_flag = 0;
	private int dering_PENGELOLA_l1_flag = 0;
	private int dering_PEMERINTAH_l1_flag = 0;
	private int dering_MASYARAKAT_l1_flag = 0;
	private int desa_PENGELOLA_l1_flag = 0;
	private int desa_PEMERINTAH_l1_flag = 0;
	private int desa_MASYARAKAT_l1_flag = 0;
	private int PILK_PENGELOLA_l1_flag = 0;
	private int PILK_PEMERINTAH_l1_flag = 0;
	private int PILK_MASYARAKAT_l1_flag = 0;

	@Override
	public void onBackPressed() {

	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		Add1.this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.add1);
		home = (LinearLayout) findViewById(R.id.home_home);
		add = (LinearLayout) findViewById(R.id.home_add);
		setting = (LinearLayout) findViewById(R.id.home_setting);
		logout = (LinearLayout) findViewById(R.id.home_logout);
		username = (TextView) findViewById(R.id.home_username);
		username.setText(Global.username);
		dat = (TextView) findViewById(R.id.home_date);
		Calendar c = Calendar.getInstance();
		System.out.println("Current time => " + c.getTime());
		SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy");
		String formattedDate = df.format(c.getTime());
		dat.setText(formattedDate);
		SharedPreferences preferences1 = getSharedPreferences(
				"desa_f1_details", MODE_PRIVATE);
		SharedPreferences.Editor editor1 = preferences1.edit();
		editor1.clear();
		editor1.commit();
		SharedPreferences preferences2 = getSharedPreferences(
				"desa_f2_details", MODE_PRIVATE);
		SharedPreferences.Editor editor2 = preferences2.edit();
		editor2.clear();
		editor2.commit();
		SharedPreferences preferences3 = getSharedPreferences(
				"desa_f3_details", MODE_PRIVATE);
		SharedPreferences.Editor editor3 = preferences3.edit();
		editor3.clear();
		editor3.commit();
		SharedPreferences preferences4 = getSharedPreferences(
				"desa_f4_details", MODE_PRIVATE);
		SharedPreferences.Editor editor4 = preferences4.edit();
		editor4.clear();
		editor4.commit();
		SharedPreferences preferences5 = getSharedPreferences(
				"desa_f5_details", MODE_PRIVATE);
		SharedPreferences.Editor editor5 = preferences5.edit();
		editor5.clear();
		editor5.commit();
		SharedPreferences preferences6 = getSharedPreferences(
				"desa_f6_details", MODE_PRIVATE);
		SharedPreferences.Editor editor6 = preferences6.edit();
		editor6.clear();
		editor6.commit();
		SharedPreferences preferences7 = getSharedPreferences(
				"desa_f7_details", MODE_PRIVATE);
		SharedPreferences.Editor editor7 = preferences7.edit();
		editor7.clear();
		editor7.commit();
		SharedPreferences preferences1a = getSharedPreferences(
				"dering_f1_details", MODE_PRIVATE);
		SharedPreferences.Editor editor1a = preferences1a.edit();
		editor1a.clear();
		editor1a.commit();
		SharedPreferences preferences2a = getSharedPreferences(
				"dering_f2_details", MODE_PRIVATE);
		SharedPreferences.Editor editor2a = preferences2a.edit();
		editor2a.clear();
		editor2a.commit();
		SharedPreferences preferences3a = getSharedPreferences(
				"dering_f3_details", MODE_PRIVATE);
		SharedPreferences.Editor editor3a = preferences3a.edit();
		editor3a.clear();
		editor3a.commit();
		SharedPreferences preferences4a = getSharedPreferences(
				"dering_f4_details", MODE_PRIVATE);
		SharedPreferences.Editor editor4a = preferences4a.edit();
		editor4a.clear();
		editor4a.commit();
		SharedPreferences preferences5a = getSharedPreferences(
				"dering_f5_details", MODE_PRIVATE);
		SharedPreferences.Editor editor5a = preferences5a.edit();
		editor5a.clear();
		editor5a.commit();
		SharedPreferences preferences6a = getSharedPreferences(
				"dering_f6_details", MODE_PRIVATE);
		SharedPreferences.Editor editor6a = preferences6a.edit();
		editor6a.clear();
		editor6a.commit();
		SharedPreferences preferences7a = getSharedPreferences(
				"dering_f7_details", MODE_PRIVATE);
		SharedPreferences.Editor editor7a = preferences7a.edit();
		editor7a.clear();
		editor7a.commit();
		SharedPreferences preferences_p1 = getSharedPreferences(
				"plik_f1_details", MODE_PRIVATE);
		SharedPreferences.Editor editorp1 = preferences_p1.edit();
		editorp1.clear();
		editorp1.commit();
		SharedPreferences preferences_p2 = getSharedPreferences(
				"plik_f2_details", MODE_PRIVATE);
		SharedPreferences.Editor editorp2 = preferences_p2.edit();
		editorp2.clear();
		editorp2.commit();
		SharedPreferences preferences_p3 = getSharedPreferences(
				"plik_f3_details", MODE_PRIVATE);
		SharedPreferences.Editor editorp3 = preferences_p3.edit();
		editorp3.clear();
		editorp3.commit();
		SharedPreferences preferences_p4 = getSharedPreferences(
				"plik_f4_details", MODE_PRIVATE);
		SharedPreferences.Editor editorp4 = preferences_p4.edit();
		editorp4.clear();
		editorp4.commit();
		SharedPreferences preferences_p5 = getSharedPreferences(
				"plik_f5_details", MODE_PRIVATE);
		SharedPreferences.Editor editorp5 = preferences_p5.edit();
		editorp5.clear();
		editorp5.commit();
		SharedPreferences preferences_p6 = getSharedPreferences(
				"plik_f6_details", MODE_PRIVATE);
		SharedPreferences.Editor editorp6 = preferences_p6.edit();
		editorp6.clear();
		editorp6.commit();
		SharedPreferences preferences_p7 = getSharedPreferences(
				"plik_f7_details", MODE_PRIVATE);
		SharedPreferences.Editor editorp7 = preferences_p7.edit();
		editorp7.clear();
		editorp7.commit();
		SharedPreferences preferences_p8 = getSharedPreferences(
				"plik_f8_details", MODE_PRIVATE);
		SharedPreferences.Editor editorp8 = preferences_p8.edit();
		editorp8.clear();
		editorp8.commit();
		dering = (RelativeLayout) findViewById(R.id.add1_dering);
		dering_l1 = (LinearLayout) findViewById(R.id.dering_l1);
		dering_masyarakat = (RelativeLayout) findViewById(R.id.add1_dering_MASYARAKAT);
		dering_MASYARAKAT_l1 = (LinearLayout) findViewById(R.id.dering_MASYARAKAT_l1);
		dering_masyarakat_2013 = (RelativeLayout) findViewById(R.id.add1_dering_MASYARAKAT_2013);
		dering_pemerintah = (RelativeLayout) findViewById(R.id.add1_dering_PEMERINTAH);
		dering_PEMERINTAH_l1 = (LinearLayout) findViewById(R.id.dering_PEMERINTAH_l1);
		dering_pemerintah_2013 = (RelativeLayout) findViewById(R.id.add1_dering_PEMERINTAH_2013);
		dering_pengelola = (RelativeLayout) findViewById(R.id.add1_dering_PENGELOLA);
		dering_PENGELOLA_l1 = (LinearLayout) findViewById(R.id.dering_PENGELOLA_l1);
		dering_pengelola_2013 = (RelativeLayout) findViewById(R.id.add1_dering_PENGELOLA_2013);
		desa = (RelativeLayout) findViewById(R.id.add1_desa);
		desa_l1 = (LinearLayout) findViewById(R.id.desa_l1);
		//desa_masyarakat = (RelativeLayout) findViewById(R.id.add1_desa_MASYARAKAT);
		//desa_MASYARAKAT_l1 = (LinearLayout) findViewById(R.id.desa_MASYARAKAT_l1);
		//desa_masyarakat_2013 = (RelativeLayout) findViewById(R.id.add1_desa_MASYARAKAT_2013);
		desa_pemerintah = (RelativeLayout) findViewById(R.id.add1_desa_PEMERINTAH);
		desa_PEMERINTAH_l1 = (LinearLayout) findViewById(R.id.desa_PEMERINTAH_l1);
		desa_pemerintah_2013 = (RelativeLayout) findViewById(R.id.add1_desa_PEMERINTAH_2013);
		//desa_pengelola = (RelativeLayout) findViewById(R.id.add1_desa_PENGELOLA);
		//desa_PENGELOLA_l1 = (LinearLayout) findViewById(R.id.desa_PENGELOLA_l1);
		//desa_pengelola_2013 = (RelativeLayout) findViewById(R.id.add1_desa_PENGELOLA_2013);
		PILK = (RelativeLayout) findViewById(R.id.add1_PILK);
		PILK_l1 = (LinearLayout) findViewById(R.id.PILK_l1);
		PILK_masyarakat = (RelativeLayout) findViewById(R.id.add1_PILK_MASYARAKAT);
		PILK_MASYARAKAT_l1 = (LinearLayout) findViewById(R.id.PILK_MASYARAKAT_l1);
		PILK_masyarakat_2013 = (RelativeLayout) findViewById(R.id.add1_PILK_MASYARAKAT_2013);
		PILK_pemerintah = (RelativeLayout) findViewById(R.id.add1_PILK_PEMERINTAH);
		PILK_PEMERINTAH_l1 = (LinearLayout) findViewById(R.id.PILK_PEMERINTAH_l1);
		PILK_pemerintah_2013 = (RelativeLayout) findViewById(R.id.add1_PILK_PEMERINTAH_2013);
		PILK_pengelola = (RelativeLayout) findViewById(R.id.add1_PILK_PENGELOLA);
		PILK_PENGELOLA_l1 = (LinearLayout) findViewById(R.id.PILK_PENGELOLA_l1);
		PILK_pengelola_2013 = (RelativeLayout) findViewById(R.id.add1_PILK_PENGELOLA_2013);
		dering_l1.setVisibility(8);
		desa_l1.setVisibility(8);
		PILK_l1.setVisibility(8);
		dering.setOnClickListener(this);
		dering_masyarakat.setOnClickListener(this);
		dering_pemerintah.setOnClickListener(this);
		dering_pengelola.setOnClickListener(this);
		desa.setOnClickListener(this);
		//desa_masyarakat.setOnClickListener(this);
		//desa_masyarakat_2013.setOnClickListener(this);
		desa_pemerintah.setOnClickListener(this);
		desa_pemerintah_2013.setOnClickListener(this);
		//desa_pengelola.setOnClickListener(this);
		//desa_pengelola_2013.setOnClickListener(this);
		dering_masyarakat_2013.setOnClickListener(this);
		dering_pemerintah_2013.setOnClickListener(this);
		dering_pengelola_2013.setOnClickListener(this);
		PILK_masyarakat_2013.setOnClickListener(this);
		PILK_pemerintah_2013.setOnClickListener(this);
		PILK_pengelola_2013.setOnClickListener(this);
		PILK.setOnClickListener(this);
		PILK_masyarakat.setOnClickListener(this);
		PILK_pemerintah.setOnClickListener(this);
		PILK_pengelola.setOnClickListener(this);

		logout.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				AlertDialog.Builder builder = new AlertDialog.Builder(Add1.this);
				builder.setTitle("Logout!!!")
						.setMessage("Are You Sure To Want To Logout?")
						.setPositiveButton("yes",
								new DialogInterface.OnClickListener() {
									public void onClick(DialogInterface dialog,
											int id) {
										Intent intent1 = new Intent(
												getApplicationContext(),
												Login.class);
										startActivity(intent1);
										Add1.this.finish();
									}
								})
						.setNegativeButton("NO",
								new DialogInterface.OnClickListener() {
									public void onClick(DialogInterface dialog,
											int id) {

									}
								}).show();
			}
		});
		setting.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent1 = new Intent(getApplicationContext(),
						Setting.class);
				startActivity(intent1);
				Add1.this.finish();
			}
		});

		home.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent1 = new Intent(getApplicationContext(), Home.class);
				startActivity(intent1);
				Add1.this.finish();
			}
		});

	}

	@Override
	public void onClick(View v) {
		if (v.getId() == dering.getId()) {
			if (dering_l1_flag == 0) {
				dering_l1.setVisibility(0);
				desa_l1.setVisibility(8);
				PILK_l1.setVisibility(8);
				dering_l1_flag = 1;
				desa_l1_flag = 0;
				PILK_l1_flag = 0;
				dering_MASYARAKAT_l1.setVisibility(8);
				dering_MASYARAKAT_l1_flag = 0;
				dering_PEMERINTAH_l1.setVisibility(8);
				dering_PEMERINTAH_l1_flag = 0;
				dering_PENGELOLA_l1.setVisibility(8);
				dering_PENGELOLA_l1_flag = 0;
			} else {
				dering_l1.setVisibility(8);
				desa_l1.setVisibility(8);
				PILK_l1.setVisibility(8);
				dering_l1_flag = 0;
				desa_l1_flag = 0;
				PILK_l1_flag = 0;
			}
		} else if (v.getId() == dering_masyarakat.getId()) {
			if (dering_MASYARAKAT_l1_flag == 0) {
				dering_MASYARAKAT_l1.setVisibility(0);
				dering_MASYARAKAT_l1_flag = 1;
			} else {

				dering_MASYARAKAT_l1.setVisibility(8);
				dering_MASYARAKAT_l1_flag = 0;
			}
		} else if (v.getId() == dering_pemerintah.getId()) {
			if (dering_PEMERINTAH_l1_flag == 0) {
				dering_PEMERINTAH_l1.setVisibility(0);
				dering_PEMERINTAH_l1_flag = 1;
			} else {
				dering_PEMERINTAH_l1.setVisibility(8);
				dering_PEMERINTAH_l1_flag = 0;
			}
		} else if (v.getId() == dering_pengelola.getId()) {
			if (dering_PENGELOLA_l1_flag == 0) {
				dering_PENGELOLA_l1.setVisibility(0);
				dering_PENGELOLA_l1_flag = 1;
			} else {

				dering_PENGELOLA_l1.setVisibility(8);
				dering_PENGELOLA_l1_flag = 0;
			}
		} else if (v.getId() == desa.getId()) {
			if (desa_l1_flag == 0) {
				dering_l1.setVisibility(8);
				desa_l1.setVisibility(0);
				PILK_l1.setVisibility(8);
				dering_l1_flag = 0;
				desa_l1_flag = 1;
				PILK_l1_flag = 0;
				//desa_MASYARAKAT_l1.setVisibility(8);
				//desa_MASYARAKAT_l1_flag = 0;
				desa_PEMERINTAH_l1.setVisibility(8);
				desa_PEMERINTAH_l1_flag = 0;
				//desa_PENGELOLA_l1.setVisibility(8);
				//desa_PENGELOLA_l1_flag = 0;
			} else {

				dering_l1.setVisibility(8);
				desa_l1.setVisibility(8);
				PILK_l1.setVisibility(8);
				dering_l1_flag = 0;
				desa_l1_flag = 0;
				PILK_l1_flag = 0;
			}
		/*
		} else if (v.getId() == desa_masyarakat.getId()) {
			if (desa_MASYARAKAT_l1_flag == 0) {
				desa_MASYARAKAT_l1.setVisibility(0);
				desa_MASYARAKAT_l1_flag = 1;
			} else {

				desa_MASYARAKAT_l1.setVisibility(8);
				desa_MASYARAKAT_l1_flag = 0;
			}
		} else if (v.getId() == desa_masyarakat_2013.getId()) {
			Global.desa_year = "2013";
			Intent intent = new Intent(getApplicationContext(),
					Desa_Form1.class);
			startActivity(intent);
			Add1.this.finish();
			*/
		} else if (v.getId() == desa_pemerintah.getId()) {
			if (desa_PEMERINTAH_l1_flag == 0) {
				desa_PEMERINTAH_l1.setVisibility(0);
				desa_PEMERINTAH_l1_flag = 1;
			} else {
				desa_PEMERINTAH_l1.setVisibility(8);
				desa_PEMERINTAH_l1_flag = 0;
			}
		
		} else if (v.getId() == desa_pemerintah_2013.getId()) {
			Global.desa_year = "2013";
			Intent intent = new Intent(getApplicationContext(),
					Desa_Form1.class);
			startActivity(intent);
			Add1.this.finish();
	/*
		} else if (v.getId() == desa_pengelola.getId()) {
			if (desa_PENGELOLA_l1_flag == 0) {
				desa_PENGELOLA_l1.setVisibility(0);
				desa_PENGELOLA_l1_flag = 1;
			} else {

				desa_PENGELOLA_l1.setVisibility(8);
				desa_PENGELOLA_l1_flag = 0;
			}
		} else if (v.getId() == desa_pengelola_2013.getId()) {
			Global.desa_year = "2013";
			Intent intent = new Intent(getApplicationContext(),
					Desa_Form1.class);
			startActivity(intent);
			Add1.this.finish();
			*/
		} else if (v.getId() == PILK_masyarakat_2013.getId()) {
			Global.plik_year = "2013";
			Intent intent = new Intent(getApplicationContext(),
					Plik_form1.class);
			startActivity(intent);
			Add1.this.finish();
		} else if (v.getId() == PILK_pemerintah_2013.getId()) {
			Global.plik_year = "2013";
			Intent intent = new Intent(getApplicationContext(),
					Plik_form1.class);
			startActivity(intent);
			Add1.this.finish();
		} else if (v.getId() == PILK_pengelola_2013.getId()) {
			Global.plik_year = "2013";
			Intent intent = new Intent(getApplicationContext(),
					Plik_form1.class);
			startActivity(intent);
			Add1.this.finish();
		} else if (v.getId() == dering_masyarakat_2013.getId()) {
			Global.dering_year = "2013";
			Intent intent = new Intent(getApplicationContext(),
					Dering_Pengelola_1.class);
			startActivity(intent);
			Add1.this.finish();
		} else if (v.getId() == dering_pemerintah_2013.getId()) {
			Global.dering_year = "2013";
			Intent intent = new Intent(getApplicationContext(),
					Dering_Pengelola_1.class);
			startActivity(intent);
			Add1.this.finish();
		} else if (v.getId() == dering_pengelola_2013.getId()) {
			Global.dering_year = "2013";
			Intent intent = new Intent(getApplicationContext(),
					Dering_Pengelola_1.class);
			startActivity(intent);
			Add1.this.finish();
		
		} else if (v.getId() == PILK.getId()) {
			if (PILK_l1_flag == 0) {
				dering_l1.setVisibility(8);
				desa_l1.setVisibility(8);
				PILK_l1.setVisibility(0);
				dering_l1_flag = 0;
				desa_l1_flag = 0;
				PILK_l1_flag = 1;
				PILK_MASYARAKAT_l1.setVisibility(8);
				PILK_MASYARAKAT_l1_flag = 0;
				PILK_PEMERINTAH_l1.setVisibility(8);
				PILK_PEMERINTAH_l1_flag = 0;
				PILK_PENGELOLA_l1.setVisibility(8);
				PILK_PENGELOLA_l1_flag = 0;
			} else {

				dering_l1.setVisibility(8);
				desa_l1.setVisibility(8);
				PILK_l1.setVisibility(8);
				dering_l1_flag = 0;
				desa_l1_flag = 0;
				PILK_l1_flag = 0;
			}
		} else if (v.getId() == PILK_masyarakat.getId()) {
			if (PILK_MASYARAKAT_l1_flag == 0) {
				PILK_MASYARAKAT_l1.setVisibility(0);
				PILK_MASYARAKAT_l1_flag = 1;
			} else {

				PILK_MASYARAKAT_l1.setVisibility(8);
				PILK_MASYARAKAT_l1_flag = 0;
			}
		} else if (v.getId() == PILK_pemerintah.getId()) {
			if (PILK_PEMERINTAH_l1_flag == 0) {
				PILK_PEMERINTAH_l1.setVisibility(0);
				PILK_PEMERINTAH_l1_flag = 1;
			} else {
				PILK_PEMERINTAH_l1.setVisibility(8);
				PILK_PEMERINTAH_l1_flag = 0;
			}
		} else if (v.getId() == PILK_pengelola.getId()) {
			if (PILK_PENGELOLA_l1_flag == 0) {
				PILK_PENGELOLA_l1.setVisibility(0);
				PILK_PENGELOLA_l1_flag = 1;
			} else {

				PILK_PENGELOLA_l1.setVisibility(8);
				PILK_PENGELOLA_l1_flag = 0;
			}
		}

	}

}
